/*     */ package com.controller;


/*     */ 
/*     */

import com.domain.Admin;
import com.domain.Student;
import com.domain.UserInfo;
import com.service.IManagerService;
import com.service.IStudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.SessionAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

/*     */
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ @SessionAttributes({"user"})
/*     */ @Controller
/*     */ @RequestMapping({"/user"})
/*     */ public class UserController
/*     */ {
/*     */   @Autowired
/*     */   private IManagerService managerService;
/*     */   @Autowired
/*     */   private IStudentService studentService;
/*     */   
/*     */   @RequestMapping({"/login"})
/*     */   public String login(@RequestParam(name = "account", required = true) String account, @RequestParam(name = "password", required = true) String password, @RequestParam(name = "userType", required = true) String userType, Model model) throws Exception {
/*  37 */     UserInfo userInfo = new UserInfo();
/*  38 */     Admin manager = null;
/*  39 */     Student student = null;
/*  40 */     String page = "";
/*  41 */     if ("管理员".equals(userType)) {
/*  42 */       manager = this.managerService.login(Integer.valueOf(Integer.parseInt(account)), password);
/*  43 */       if (manager != null) {
/*  44 */         userInfo.setUserId(manager.getId());
/*  45 */         userInfo.setUserName(manager.getName());
/*  46 */         userInfo.setUserType("管理员");
/*  47 */         model.addAttribute("user", userInfo);
/*  48 */         return "main";
/*     */       } 
/*     */     } 
/*  51 */     if ("学生".equals(userType)) {
/*  52 */       student = this.studentService.login(account, password);
/*  53 */       if (student != null) {
/*  54 */         userInfo.setUserId(student.getSid());
/*  55 */         userInfo.setUserName(student.getName());
/*  56 */         userInfo.setUserType("学生");
/*  57 */         model.addAttribute("user", userInfo);
/*  58 */         return "main";
/*     */       } 
/*     */     } 
/*  61 */     if (userInfo.getUserId() == null) {
/*  62 */       page = "404";
/*     */     }
/*  64 */     return page;
/*     */   }
/*     */   
/*     */   @RequestMapping({"/logout"})
/*     */   public void logout(HttpSession session, HttpServletResponse response, HttpServletRequest request) throws Exception {
/*  69 */     UserInfo userInfo = (UserInfo)session.getAttribute("user");
/*  70 */     session.removeAttribute("user");
/*  71 */     UserInfo userInfo1 = (UserInfo)session.getAttribute("user");
/*  72 */     response.sendRedirect(request.getContextPath() + "/login.jsp");
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @RequestMapping({"/findAllAdmin"})
/*     */   public String findAll(Model model) throws Exception {
/*  83 */     List<Admin> adminList = this.managerService.getAllAdmin();
/*  84 */     model.addAttribute("admins", adminList);
/*  85 */     return "/admin/admin_all";
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @RequestMapping({"/404"})
/*     */   public String error() {
/*  93 */     return "404";
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @RequestMapping({"/forget-password"})
/*     */   public String forget(@RequestParam("name") String name, @RequestParam("no") String no, @RequestParam("phone") String phone, Model model) {
/* 107 */     Student student = new Student();
/* 108 */     student.setName(name);
/* 109 */     student.setNo(no);
/* 110 */     student.setPhone(phone);
/* 111 */     List<Student> studentList = this.studentService.getStuForget(student);
/* 112 */     if (studentList.size() == 1) {
/* 113 */       model.addAttribute("name", student.getName());
/* 114 */       return "/student/forget-update";
/*     */     } 
/* 116 */     model.addAttribute("msg", "信息填写有误!!!");
/* 117 */     return "/student/forget-password";
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @RequestMapping({"/forget-update"})
/*     */   public void update(@RequestParam("name") String name, @RequestParam("password1") String password, HttpServletRequest request, HttpServletResponse response) throws IOException {
/* 131 */     Student student = new Student();
/* 132 */     student.setName(name);
/* 133 */     student.setPassword(password);
/* 134 */     int result = this.studentService.updatePasswordByName(student);
/* 135 */     if (result >= 1) {
/* 136 */       response.sendRedirect(request.getContextPath() + "/login.jsp");
/*     */     } else {
/* 138 */       response.sendRedirect(request.getContextPath() + "/pages/404.jsp");
/*     */     } 
/*     */   }
/*     */ }


/* Location:              G:\项目\图书管理系统\library_system-1.0-SNAPSHOT.war!\WEB-INF\classes\com\controller\UserController.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */